package ar.com.digitalbricks.view.imprenta.cliente.action;

import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;

import org.apache.struts2.interceptor.SessionAware;

import ar.com.digitalbricks.fwk.hbm.ActionTransactionSupportAbstract;
import ar.com.digitalbricks.imprenta.cliente.mgr.ClienteMgr;
import ar.com.digitalbricks.imprenta.persona.enums.TipoMedioComunicacion;
import ar.com.digitalbricks.imprenta.persona.mgr.ContactoMgr;
import ar.com.digitalbricks.view.imprenta.general.EnumView;
import ar.com.digitalbricks.view.imprenta.general.ModuloAction;
import ar.com.digitalbricks.view.imprenta.helper.ClienteView;
import ar.com.digitalbricks.view.imprenta.helper.ContactoView;
import ar.com.digitalbricks.view.imprenta.helper.action.ViewHelperAction;

import com.opensymphony.xwork2.Action;

public class ClienteAction extends ActionTransactionSupportAbstract implements SessionAware, ModuloAction{
	private ClienteView clienteView;
	private Boolean showContacto;
	private Boolean showTelefono;
	private Boolean showMsg;
	
	private String msg;

	private static ContactoMgr contactoMgr;
	private static ClienteMgr clienteMgr;
	private static ViewHelperAction viewHelper;
	private static Random random;
	
	protected Map<String, Object> session;

	@Override
	public String execute() throws Exception {
		session.put("contactos", new HashSet<ContactoView>());
		return Action.SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public Collection<ContactoView> getContactos(){
		return (Collection<ContactoView>) session.get("contactos");
	}
	
	/***********************
	 * GETTERS AND SETTERS *
	 *******************//**/

	public ClienteMgr getClienteMgr() {
		return clienteMgr;
	}
	
	public void setClienteMgr(ClienteMgr clienteMgr) {
		ClienteAction.clienteMgr = clienteMgr;
	}
	
	public ClienteView getClienteView() {
		if (this.clienteView == null){
			this.clienteView = new ClienteView();
		}
		return this.clienteView;
	}

	public void setClienteView(ClienteView clienteView) {
		this.clienteView = clienteView;
	}

	public ContactoMgr getContactoMgr() {
		return contactoMgr;
	}

	public void setContactoMgr(ContactoMgr contactoMgr) {
		ClienteAction.contactoMgr = contactoMgr;
	}

	@Override
	public void setSession(Map<String, Object> map) {
		session = map;
	}
	
	public Map<String, Object> getSession() {
		return this.session;
	}

	public ViewHelperAction getViewHelper() {
		return viewHelper;
	}

	public void setViewHelper(ViewHelperAction viewHelper) {
		ClienteAction.viewHelper = viewHelper;
	}

	@Override
	public String getRutaCss() {
		return "css/cliente/principal.css";
	}

	@Override
	public String getTitulo() {
		return "cliente.titulo";
	}
	
	public Boolean getShowContacto() {
		return this.showContacto;
	}

	public Boolean getShowTelefono() {
		return this.showTelefono;
	}

	public void setShowContacto(Boolean showContacto) {
		this.showContacto = showContacto;
	}

	public void setShowTelefono(Boolean showTelefono) {
		this.showTelefono = showTelefono;
	}

	public String getShowContactoDiv() {
		return this.toCssLanguage(this.getShowContacto());
	}

	public String getShowTelefonoDiv() {
		return this.toCssLanguage(this.getShowTelefono());
	}
	
	public String getShowMsgDiv(){
		return this.toCssLanguage(this.getShowMsg());
	}
	
	private String toCssLanguage(Boolean show){
		if (show != null && show){
			return "display";
		}else{
			return "display:none";
		}
	}

	@SuppressWarnings("unchecked")
	public Collection<EnumView> getTiposTelefono() {
		Collection<EnumView> tipos = new HashSet<EnumView>();
		for (Enum aEnum : EnumSet.allOf(TipoMedioComunicacion.class)){
			tipos.add(new EnumView(aEnum));
		}
		return tipos;
	}

	public Boolean getShowMsg() {
		return this.showMsg;
	}

	public String getMsg() {
		return this.msg;
	}

	public void setShowMsg(Boolean showMsg) {
		this.showMsg = showMsg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Random getRandom() {
		return random;
	}

	public void setRandom(Random random) {
		ClienteAction.random = random;
	}
}